package com.homeworkh.usermanagementserver.aop;

/**
 * @author lq
 * @date 2021/1/14 9:21
 */
public class StaticProxy implements Subject {
    private Subject realSubject;

    public StaticProxy(Subject subject){
        this.realSubject = subject;
    }

    public void before(String param){
        if (!param.equals("magic")){
            throw new IllegalArgumentException();
        }
    }

    @Override
    public void request(String param) {
        before(param);
        realSubject.request(param);
    }


    public static void main(String[] args) {
        System.getProperties().put("jdk.proxy.ProxyGenerator.saveGeneratedFiles","true");
        Subject  subject = new RealSubject();
        subject.request("magic");
        StaticProxy staticProxy = new StaticProxy(subject);
        staticProxy.request("magic");
        staticProxy.request("magic");
    }
}
